﻿using System;

namespace FBGraph.Controllers
{
    /// <summary>Provides basic access to Facebook's FQL API.</summary>
    /// <remarks>
    /// <para>More documentation can be found at Facebook's <a href="http://developers.facebook.com/docs/reference/fql/">FQL Documentation</a>.</para>
    /// </remarks>
    public class FqlController : FBGraphController
    {
        /// <summary>The standard url format used for making FQL qs requests.</summary>
        protected const String FQL_QUERY_URL_FORMAT = "https://api.facebook.com/method/fql.qs?qs={0}";

        /// <summary>Initializes an instance of <see cref="FqlController" />.</summary>
        /// <param name="context">A reference to the containing <see cref="IFBGraphContext" /> implementation.</param>
        public FqlController(IFBGraphContext context) : base(context) { }

        /// <summary>Executes the specified FQL qs.</summary>
        /// <typeparam name="TModel">The type that will be returned by the qs.</typeparam>
        /// <param name="query">The FQL query to execute.</param>
        /// <returns>An array of <typeparamref name="TModel" />.</returns>
        public ListResult<TModel> Query<TModel>(String query)
        {
            var uri = new Uri(String.Format(FQL_QUERY_URL_FORMAT, query));
            var result = Context.Get<ListResult<TModel>>(uri);
            return result;
        }
    }
}